<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/13
 * Time: 13:40
 */

namespace Modules\Api\Service;

use HiCommon\Model\OrderRepairstore;
use HiCommon\Repository\InvoiceRepository;
use HiCommon\Repository\InvoiceApplyRepository;
use HiCommon\Repository\InvoiceApplyExtendRepository;
use HiCommon\Repository\RoadRescueOrderRepository;
use HiCommon\Repository\StoreOrderRepository;
use HiCommon\Repository\OrderRepairstoreRepository;
use HiCommon\Repository\OrderCheckpointRepository;
use HiCommon\Repository\AddressRepository;

class InvoiceService extends BaseService
{

	/**
	 *	获取发票信息
	 *	hinq 2019 11 19
	 *
	 **/
	public function get_one(){
		try{
			$user_id = api_user_id();
			$where = ['user_id'=>$user_id , 'status'=>1];
			//获取登录用户的所有已经申请的发票信息
			$info = InvoiceRepository::get_one_where( (array) $where );
			if( empty( $info ) ){
                $info =null;
            }
			return hello_success('ok',$info);
		}catch( \Exception $exception ){
			return ['state'=>1,'msg'=>$exception->getMessage()];
		}
	}


	/**
	 *  验证前端提交的数据
     *  hinq 2020 3 18
     *
     **/
	public function check_data( array $arr_input ){

	    if( $arr_input['type'] == 1 ){   // 个人发票
            if( empty( $arr_input['name'] ) ){
                return hello_error('个人姓名不能为空');
            }
            if( $arr_input['cate'] == 1 ){  //电子版
                if( empty( $arr_input['emile'] ) ){
                    return hello_error('电子邮箱不能为空');
                }
            }else if( $arr_input['cate'] == 2 ){     //纸质版
                if( empty( $arr_input['address_id'] ) ){
                    return hello_error('收货地址不能为空');
                }
            }
        }else if( $arr_input['type'] == 2 ){  //企业发票
            if( empty( $arr_input['company_name'] ) ){
                return hello_error('企业名称不能为空');
            }
            if( empty( $arr_input['code'] ) ){
                return hello_error('企业识别码不能为空');
            }
            if( $arr_input['cate'] == 1 ){   //电子版
                if( empty( $arr_input['company_email'] ) ){
                    return hello_error('企业邮箱不能为空');
                }
            }else if( $arr_input['cate'] == 2 ){   //纸质版
                if( empty( $arr_input['address_id'] ) ){
                    return hello_error('收货地址不能为空');
                }
            }
//            if( empty( $arr_input['company_email'] ) ){
//                return hello_error('企业邮箱不能为空');
//            }
        }
//	    return hello_success('ok' ,$arr_input );
        return $arr_input;
    }

	/**
	 *	添加、编辑基本发票信息
	 *	hinq 2019 11 19
	 *
	 **/
	public function add_one( array $arr_input ){
		try{
            $user_id = api_user_id();
            //验证当前用户是否已经添加过
            $info = InvoiceRepository::get_one_where((array) ['user_id'=>$user_id]);
            if( empty( $info ) ){  //添加
                $data['user_id'] = $user_id;
                $temp = self::check_data( (array) $arr_input );
                if( $arr_input['type'] == 1 ){   //个人
                     if( $temp['state'] == 1 ){
                         return $temp;
                     }
                     $data['name'] = $arr_input['name'];   //真实姓名
                     $data['email'] = $arr_input['email'];  //电子邮箱
                     $res = InvoiceRepository::add_one( (array) $data );
                     if( empty( $res ) ) {
                         return hello_error('失败');
                     }
                     return hello_success('成功');
                }else{  //企业
                     if( $temp['state'] == 1 ){
                         return $temp;
                     }
                     $data['company_name'] = $temp['company_name'];     //公司名称
                     $data['company_email'] = $temp['company_email'];       //公司邮箱
                     $data['code'] = $temp['code'];     //企业识别码
                     $data['address'] = empty( $temp['address'] ) ? '' : $temp['address'];      //非必填字段     公司开户地址
                     $data['phone'] = empty( $temp['phone'] ) ? '' : $temp['phone'];            //非必填字段     公司电话
                     $data['bankname'] = empty( $temp['bankname'] ) ? '' : $temp['bankname'];   //非必填字段     公司开户银行
                     $data['bank_num'] = empty( $temp['bank_num'] ) ? '' : $temp['bank_num'];   //非必填字段     公司银行卡号
                     $res = InvoiceRepository::add_one( (array) $data );
                     if( empty( $res ) ) {
                         return hello_error('失败');
                     }
                     return hello_success('成功');
                 }
            }else{  //编辑
                if( $arr_input['type'] == 1 ){   //个人
                    $temp = self::check_data( (array) $arr_input );
                    if( $temp['state'] == 1 ){
                        return $temp;
                    }

                    $data['name'] = $arr_input['name'];
                    $data['email'] = $arr_input['email'];
                    $data['id'] = $info['id'];

                    $res = InvoiceRepository::edit_one( (array) $data );
                    if( empty( $res ) ) {
                        return hello_error('失败');
                    }
                    return hello_success('成功');
                }else{  //企业
                    $temp = self::check_data( (array) $arr_input );
                    if( $temp['state'] == 1 ){
                        return $temp;
                    }
                    $data['company_name'] = $temp['company_name'];      //公司名称
                    $data['company_email'] = $temp['company_email'];        //公司邮箱
                    $data['code'] = $temp['code'];            //企业识别码
                    $data['address'] = empty( $temp['address'] ) ? '' : $temp['address'];      //非必填字段      公司开户地址
                    $data['phone'] = empty( $temp['phone'] ) ? '' : $temp['phone'];            //非必填字段      公司电话
                    $data['bankname'] = empty( $temp['bankname'] ) ? '' : $temp['bankname'];   //非必填字段      公司开户银行
                    $data['bank_num'] = empty( $temp['bank_num'] ) ? '' : $temp['bank_num'];   //非必填字段      公司银行卡号

                    $data['id'] = $info['id'];
                    $res = InvoiceRepository::edit_one( (array) $data );
                    if( empty( $res ) ) {
                        return hello_error('失败');
                    }
                    return hello_success('成功');
                }
            }
		}catch( \Exception $exception ){
			return ['state'=>1,'msg'=>$exception->getMessage()];
		}
	}


	/**
	 *	申请发票信息
	 *	hinq 2019 11 19
	 *  后台处理完发票信息后 后台需要给用户发送一条短信
	 **/
	public function apply_invoice( array $arr_input ){
        \DB::beginTransaction();
		try{
            $arr_temp = json_decode( $arr_input['params'] , true );  //前端提交过来的数据是加密的
            $user_id = api_user_id();
            $data['user_id'] = $user_id;
            $data['type'] = $arr_temp['type'];
            $data['cate'] = $arr_temp['cate'];   //1：电子版  2纸制版

            if( $data['type'] == 1 ){  //个人
                if( empty( $arr_temp['name'] ) ){
                    return hello_error('真实姓名不能为空');
                }
                $data['name'] = $arr_temp['name'];
                if( $arr_temp['cate'] == 1 ){   //电子版
                    if( empty( $arr_temp['email'] ) ){
                        return hello_error('电子邮箱不能为空');
                    }
                    $data['email'] = $arr_temp['email'];
                }else{  //纸质版
                    if( empty( $arr_temp['address_id'] ) ){
                        return hello_error('收件地址不能为空');
                    }
                    $data['address_id'] = $arr_temp['address_id'];
                }
            }else{   //企业
                if( empty( $arr_temp['company_name'] ) ){
                    return hello_error('发票抬头不能为空');
                }
                if( empty( $arr_temp['code'] ) ){
                    return hello_error('企业识别码不能为空');
                }
                if( $arr_temp['cate'] == 1 ){    //电子版
                    if( empty( $arr_temp['company_email'] ) ){
                        return hello_error('企业邮箱不能为空');
                    }
//                    $data['company_email'] = $arr_temp['company_email'];
                }else{   //纸质版
                    if( empty( $arr_temp['address_id'] ) ){
                        return hello_error('收件地址不能为空');
                    }
                    $data['address_id'] = $arr_temp['address_id'];
                }



                $data['company_name'] = $arr_temp['company_name'];
                $data['code'] = $arr_temp['code'];
                $data['apply_address'] = empty($arr_temp['apply_address']) ? '':$arr_temp['apply_address'];
                $data['phone'] = empty($arr_temp['phone']) ? '':$arr_temp['phone'];
                $data['bankname'] = empty($arr_temp['bankname']) ? '':$arr_temp['bankname'];
                $data['bank_num'] = empty($arr_temp['bank_num']) ? '':$arr_temp['bank_num'];
                $data['company_email'] = empty($arr_temp['company_email']) ? '':$arr_temp['company_email'];
            }
            if( empty( $arr_temp['list'] ) ){
                return hello_error('请选择需要开发票的订单');
            }
            //保存收货地址信息
            if( !empty( $data['address_id'] ) ){
                $where['id'] = $data['address_id'];
                $arr_option['field'] = ['username','phone','province','city','area','address'];
                $arr_address = AddressRepository::get_one_new( $where , $arr_option);
                if( empty( $arr_address->first() ) ){
                    return hello_error('地址信息错误，请重新选择地址');
                }
                $arr_address = $arr_address->toarray();

                $data['username'] = $arr_address['username'];
                $data['address_phone'] = $arr_address['phone'];
                $data['province'] = $arr_address['province'];
                $data['city'] = $arr_address['city'];
                $data['area'] = $arr_address['area'];
                $data['address'] = $arr_address['address'];
            }
            foreach ( $arr_temp['list'] as $key=>$vo ){//之前可以多商户多订单提交数据  现在只能提交一个商家的数据  这层循环可不要
                if( empty( $vo['order_id'] ) ){
                    return hello_error('请选择订单');
                }
                $data['repairstore_id'] = $vo['shop_id'];
                $data['order_type'] = $arr_temp['order_type'];

                $res = InvoiceApplyRepository::add_one( (array) $data );   //添加发票的主体信息
                $ids = explode(',', $vo['order_id'] );   //订单id集合
                $res3 = true;
                //修改订单的开票状态 防止同一订单多次开票
                $arr_where = [
                    "key" => 'id',
                    "value" => $ids
                ];
                $arr_input2['is_invoice'] = 2; // 开票状态设置为申请中
                if( $arr_temp['order_type'] == 1 ){   //普通订单
                    //检测当前订单是否允许开发票
                    $count = StoreOrderRepository::get_count_whereIn( (array) $arr_where  );
                    if( $count > 0 ){
                        return hello_error('该订单已开发票或已申请开发票，请重新选择订单');
                    }
                    $res3 = StoreOrderRepository::edit_one_whereIn( (array) $arr_where , (array) $arr_input2);
                }else if( $arr_temp['order_type'] == 2 ){   //服务订单
                    //检测当前订单是否允许开发票
                    $count = OrderRepairstoreRepository::get_count_whereIn( (array) $arr_where  );
                    if( $count > 0 ){
                        return hello_error('该订单已开发票或已申请开发票，请重新选择订单');
                    }
                    $res3 = OrderRepairstoreRepository::edit_one_whereIn( (array) $arr_where , (array) $arr_input2);
                }else if( $arr_temp['order_type'] == 3 ){   //预约订单
                    //检测当前订单是否允许开发票
                    $count = OrderCheckpointRepository::get_count_whereIn( (array) $arr_where  );
                    if( $count > 0 ){
                        return hello_error('该订单已开发票或已申请开发票，请重新选择订单');
                    }
                    $res3 = OrderCheckpointRepository::edit_one_whereIn( (array) $arr_where , (array) $arr_input2);
                }else if( $arr_temp['order_type'] == 4 ){   //道路救援订单
                    //检测当前订单是否允许开发票
                    $count = RoadRescueOrderRepository::get_count_whereIn( (array) $arr_where  );
                    if( $count > 0 ){
                        return hello_error('该订单已开发票或已申请开发票，请重新选择订单');
                    }
                    $res3 = RoadRescueOrderRepository::edit_one_whereIn( (array) $arr_where , (array) $arr_input2);
                }
                $res2 = true;
                if( count( $ids ) > 0 ){
                    $data_extend['link_id'] = $res->id;
                    $data_extend['type'] = $arr_temp['order_type'];
                    foreach ($ids as $key => $value) {
                        $data_extend['goods_order_id'] = $value;
                        $res2 = InvoiceApplyExtendRepository::add_one( (array) $data_extend );   //添加发票关联的订单信息
                    }
                }
                if( $res && $res2 && $res3 ){
                    \DB::commit();
                    return hello_success('ok');
                }
            }
            return hello_success('ok');
		}catch( \Exception $exception ){
			return ['state'=>1,'msg'=>$exception->getMessage()];
		}
	}

    /**
     *	获取需要打印发票的订单
     *	hinq 2019 11 21
     *
     **/
    public function invoice_order( array $arr_input ){
        try{
            $user_id = api_user_id();

            $arr_where = ['user_id'=>$user_id];
            $arr_list = [];   //门店名称信息
            $ids = [];  //所有发生交易的商品id
            if( $arr_input['type'] == 1 ){    //普通订单
                //获取当前用户购买商品的所有门店【按门第分组，最总获取的是当前用户于所有门店发生过关系的列表】
                $arr_shop = StoreOrderRepository::get_shop_list( (array) $arr_where );

                foreach ( $arr_shop as $key => $value ){
                    $arr_list[$key]['id'] = $value['shop']['id'];
                    $arr_list[$key]['name'] = $value['shop']['name'];
                    $arr_list[$key]['logo'] = $value['shop']['logo']['full_src'];
                    $ids[] = $value['shop_id'];
                }
                //获取当前用户所有未开发票的普通订单（含活动订单）
                $arr_option['where'] = ['is_invoice'=>0,'pay_status'=>2,'status'=>20 , 'user_id'=>$user_id];  //is_invoice  0：未开发票  1：已开发票    pay_type   1：未支付  2：已支付
                $arr_option['field'] = ['id','order_no','goods_num','pay_amount','shop_id','created_at'];
                $arr_option['with'] = ['getOrderGoods2'];
                $arr_order = StoreOrderRepository::get_all_wherein( (array) $ids , (array) $arr_option )->toArray();
                $data = [];
                foreach ( $arr_list as $key => &$value ){
                    $temp = [];
                    foreach ($arr_order as $k => &$vo) {
                        if ($vo['shop_id'] == $value['id']) {
                            $temp['pay_amount'] = $vo['pay_amount'];
                            $temp['name'] = $vo['get_order_goods2'][0]['goods_name'];
                            $temp['pic_url'] = $vo['get_order_goods2'][0]['goods_pic']['full_src'];
                            $temp['created_at'] = $vo['created_at'];
                            $temp['order_no'] = $vo['order_no'];
                            $temp['id'] = $vo['id'];
                            $value['order'][] = $temp;
                        }
                    }
                    if( !empty( $value['order'] ) ){
                        $data[] = $value;
                    }
                }
                return hello_success('ok',$data);
            }else if( $arr_input['type'] == 2 ){    //服务订单
                //获取当前用户购买商品的所有门店
                $arr_repairstore = OrderRepairstoreRepository::get_shop_list( (array) $arr_where )->toArray();
                foreach ( $arr_repairstore as $key => $value ){
                    $arr_list[$key]['id'] = $value['shop']['id'];
                    $arr_list[$key]['name'] = $value['shop']['name'];
                    $arr_list[$key]['logo'] = $value['shop']['logo']['full_src'];
                    $ids[] = $value['shop_id'];   //所有门店的id集合
                }
                //获取当前用户所有未开发票的服务订单
                $arr_option['where'] = ['is_invoice'=>0,'pay_status'=>1,'status'=>4,'user_id'=>$user_id];   // is_invoice  0：未开发票  1：已开发票    pay_type   1：已支付
                $arr_option['field'] = ['id','order_number','goods_num','pay_price','shop_id','repairstore_goods_id','created_at'];
                $arr_option['with'] = ['repairstore_goods','repairstore_goods.pic'];
                $arr_order = OrderRepairstoreRepository::get_all_wherein( (array) $ids , (array) $arr_option )->toArray();
                $data = [];
                foreach ( $arr_list as $key => &$value ){
                    $temp = [];
                    foreach ($arr_order as $k => $vo) {
                        //友好的将订单信息录入到指定的门店下面
                        if ($vo['shop_id'] == $value['id']) {
                            $temp['pay_amount'] = $vo['pay_price'];
                            $temp['name'] = $vo['repairstore_goods']['name'];
                            $temp['pic_url'] = $vo['repairstore_goods']['pic']['full_src'];
                            $temp['created_at'] = $vo['created_at'];
                            $temp['order_no'] = $vo['order_number'];
                            $temp['id'] = $vo['id'];
                            $value['order'][] = $temp;
                        }
                    }
                    if( !empty( $value['order'] ) ){
                        $data[] = $value;
                    }
                }
                return hello_success('ok',$data);
            }else if( $arr_input['type'] == 3 ){    //预约订单
                //获取当前用户购买商品的所有门店
                $arr_repairstore = OrderCheckpointRepository::get_shop_list( (array) $arr_where )->toArray();

                foreach ( $arr_repairstore as $key => $value ){
                    $arr_list[$key]['id'] = $value['shop']['id'];
                    $arr_list[$key]['name'] = $value['shop']['name'];
                    $arr_list[$key]['logo'] = $value['shop']['logo']['full_src'];
                    $ids[] = $value['shop_id'];   //所有门店的id集合
                }

                //获取当前用户所有未开发票的服务订单
                $arr_option['where'] = ['is_invoice'=>0,'pay_state'=>2,'complete_state'=> 2 ,'user_id'=>$user_id];  // is_invoice  0：未开发票  1：已开发票    pay_type   1：未支付
                $arr_option['field'] = ['id','order_sn','appointment_num','price','shop_id','created_at'];
                $arr_order = OrderCheckpointRepository::get_all_wherein( (array) $ids , (array) $arr_option )->toArray();
                $data = [];
                foreach ( $arr_list as $key => &$value ){
                    $temp = [];
                    foreach ($arr_order as $k => $vo) {
                        if ($vo['shop_id'] == $value['id']) {
                            $temp['pay_amount'] = $vo['price'];
                            $temp['name'] = '';
                            $temp['pic_url'] = '';
                            $temp['created_at'] = $vo['created_at'];
                            $temp['order_no'] = $vo['order_sn'];
                            $temp['id'] = $vo['id'];
                            $value['order'][] = $temp;
                        }
                    }
                    if( !empty( $value['order'] ) ){
                        $data[] = $value;
                    }
                }
                return hello_success('ok',$data);
            }else if( $arr_input['type'] == 4 ){  //道路救援
                //获取当前用户购买商品的所有门店
                $arr_option2['where'] = ['user_id'=>$user_id ];
                $arr_option2['with'] = ['to_shop'=>function($query){
                    $query->select(['id','name','logo','phone','address','longitude','latitude']);
                }];
                $arr_repairstore = RoadRescueOrderRepository::get_shop_list( (array) $arr_option2 )->toArray();
                foreach ( $arr_repairstore as $key => $value ){
                    $arr_list[$key]['id'] = $value['to_shop']['id'];
                    $arr_list[$key]['name'] = $value['to_shop']['name'];
                    $arr_list[$key]['logo'] = $value['to_shop']['logo']['full_src'];
                    $ids[] = $value['shop_id'];   //所有门店的id集合
                }

                //获取当前用户所有未开发票的道路救援订单
                $arr_option['where'] = ['is_invoice'=>0,'pay_status'=>1 , 'user_id'=>$user_id ,'status'=>3];  // is_invoice  0：未开发票  1：已开发票    pay_type   1：已支付
                $arr_option['field'] = ['id','order_sn','price','shop_id','created_at','pid'];
//                $arr_option['with'] = ['user_apprise'];
                $arr_order = RoadRescueOrderRepository::get_all_wherein( (array) $ids , (array) $arr_option )->toArray();
                $type_list = road_rescue_server_type();
                foreach ( $type_list as $key => $vo ){
                    $arr_types[$vo['id']] = $vo['name'];
                    $arr_type_images[$vo['id']] = $vo['image'];
                }
                $data = [];
                foreach ( $arr_list as $key => &$value ){
                    $temp= [];
                    foreach ($arr_order as $k => &$vo) {
                        if ( $vo['shop_id'] == $value['id'] ) {
                            $temp['pay_amount'] = $vo['price'];
                            $temp['name'] = $arr_types[$vo['pid']];
                            $temp['pic_url'] = $arr_type_images[$vo['pid']];
                            $temp['created_at'] = $vo['created_at'];
                            $temp['order_no'] = $vo['order_sn'];
                            $temp['id'] = $vo['id'];
                            $value['order'][] = $temp;
                        }
                    }
                    if( !empty( $value['order'] ) ){
                        $data[] = $value;
                    }
                }
                return hello_success('ok',$data);
            }
        }catch( \Exception $exception ){
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }
    }


    /**
     *  获取用户申请的发票列表
     *  hinq 2020 5 8
     *  如果董小姐会对宋冬野说晚安  如果阿刁的世界都是美好
     **/
    public function apply_list( array $arr_input ){
        try{

            $arr_optionp['where'] = ['user_id'=>api_user_id()];
            $arr_optionp['field'] = ['id','user_id','repairstore_id','type','cate','name','email','company_name','code','apply_address'
                ,'phone','bankname','bank_num','status','created_at','company_email','goods_order','address_id','order_type'
                ,'shenqin_status','number','content','username','address_phone','province','city','area','address'];
            $arr_optionp['with'] = ['extend'=>function( $query ){
                $query->select('id','goods_order_id','link_id','type');
            },'extend.order_roadrescus','extend.order'=>function( $query ){
                $query->select('id','order_no','pay_amount','is_invoice');
            },'extend.order_repairstore','extend.order_checkpoint'];

            $arr_list = InvoiceApplyRepository::get_list( (array) $arr_optionp , (array) $arr_input )->toarray();
            $temp = [];

            foreach ( $arr_list['data'] as $key => &$vo ){
                $all_price = 0;
                $ids = '';
                foreach ( $vo['extend'] as $k => $v){
                    $ids .=','.$v['goods_order_id'];
                    if( $vo['order_type'] == 1 ){  // 1：普通订单  2：服务订单  3：预约订单 4:道路救援
                        $all_price =  (int) ($v['order']['pay_amount'] * 100 + $all_price);
                    }else if( $vo['order_type'] == 2 ){  //  2：服务订单
                        $all_price =  (int) ($v['order_repairstore']['pay_price'] * 100 + $all_price);
                    }else if( $vo['order_type'] == 3 ){  // 3：预约订单
                        $all_price =  (int) ($v['order_checkpoint']['price'] * 100 + $all_price);
                    }else if( $vo['order_type'] == 4 ){  // 4:道路救援
                        $all_price =  (int) ($v['order_roadrescus']['price'] * 100 + $all_price);
                    }
                }

                $temp[$key]['id'] = $vo['id'];
                $temp[$key]['cate'] = $vo['cate']['id'];
                $temp[$key]['type'] = $vo['type']['id'];
                $temp[$key]['type_msg'] = $vo['type']['name'];
                $temp[$key]['name'] = $vo['name'];
                $temp[$key]['company_name'] = $vo['company_name'];
                $temp[$key]['created_at'] = $vo['created_at'];
                $temp[$key]['price'] = (string) ( $all_price / 100) ;
                $temp[$key]['all_num'] = count( $vo['extend'] );
                $temp[$key]['status'] = $vo['shenqin_status'];    //1：申请中  2：已开发票  3：拒绝开票
                $temp[$key]['email'] = $vo['email'];
                $temp[$key]['code'] = $vo['code'];
                $temp[$key]['apply_address'] = $vo['apply_address'];
                $temp[$key]['phone'] = $vo['phone'];
                $temp[$key]['bankname'] = $vo['bankname'];
                $temp[$key]['bank_num'] = $vo['bank_num'];
                $temp[$key]['company_email'] = $vo['company_email'];
                $temp[$key]['content'] = $vo['content'];
                $temp[$key]['number'] = $vo['number'];
                $temp[$key]['address'] = [
                    "id" => $vo['address_id'],
                    "username" => $vo['username'],
                    "phone" => $vo['address_phone'],
                    "province" => $vo['province'],
                    "city" => $vo['city'],
                    "area" => $vo['area'],
                    "address" => $vo['address'],
                ];
                $temp[$key]['list'] = [
                    "shop_id" => $vo['repairstore_id'],
                    "order_id" => trim( $ids ,',')
                ];
                $temp[$key]['order_type'] = $vo['order_type'];

            }

            $res['page_data'] = [
                'current_page'=>$arr_list['current_page'],
                'last_page'=>$arr_list['last_page'],
                'per_page'=>$arr_list['per_page'],
                'total'=>$arr_list['total'],
            ];
            $res['data'] = $temp;
            return hello_success('ok' , $res );
        }catch (\Exception $exception){
            return hello_error( $exception->getMessage() );
        }
    }




}